<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Modifying Feed and Entry structures - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.feed.modifying-feed.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.feed.modifying-feed.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.feed.consuming-atom-single-entry.html">Consuming a Single Atom Entry</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.feed.html">Zend_Feed</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.feed.custom-feed.html">Custom Feed and Entry Classes</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.feed.modifying-feed" class="section"><div class="info"><h1 class="title">Modifying Feed and Entry structures</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Feed</span>&#039;s natural syntax extends to constructing and modifying
        feeds and entries as well as reading them. You can easily turn your new or modified objects
        back into well-formed <acronym class="acronym">XML</acronym> for saving to a file or sending to a server.
    </p>

    <div class="example" id="zend.feed.modifying-feed.example.modifying"><div class="info"><p><b>Example #1 Modifying an Existing Feed Entry</b></p></div>
        

        <pre class="programlisting brush: php">
$feed = new Zend_Feed_Atom(&#039;http://atom.example.com/feed/1&#039;);
$entry = $feed-&gt;current();

$entry-&gt;title = &#039;This is a new title&#039;;
$entry-&gt;author-&gt;email = &#039;my_email@example.com&#039;;

echo $entry-&gt;saveXML();
</pre>


        <div class="example-contents"><p>
            This will output a full (includes <strong class="command">&lt;?xml ... &gt;</strong> prologue)
            <acronym class="acronym">XML</acronym> representation of the new entry, including any necessary
            <acronym class="acronym">XML</acronym> namespaces.
        </p></div>

        <div class="example-contents"><p>
            Note that the above will work even if the existing entry does not already have an author
            tag. You can use as many levels of <strong class="command">-&gt;</strong> access as you like before
            getting to an assignment; all of the intervening levels will be created for you
            automatically if necessary.
        </p></div>
    </div>

    <p class="para">
        If you want to use a namespace other than <strong class="command">atom:</strong>, <strong class="command">rss:</strong>,
        or <strong class="command">osrss:</strong> in your entry, you need to register the namespace with
        <span class="classname">Zend_Feed</span> using
         <span class="methodname">Zend_Feed::registerNamespace()</span>. When you are modifying an existing
        element, it will always maintain its original namespace. When adding a new element, it will
        go into the default namespace if you do not explicitly specify another namespace.
    </p>

    <div class="example" id="zend.feed.modifying-feed.example.creating"><div class="info"><p><b>Example #2 Creating an Atom Entry with Elements of Custom Namespaces</b></p></div>
        

        <pre class="programlisting brush: php">
$entry = new Zend_Feed_Entry_Atom();
// id is always assigned by the server in Atom
$entry-&gt;title = &#039;my custom entry&#039;;
$entry-&gt;author-&gt;name = &#039;Example Author&#039;;
$entry-&gt;author-&gt;email = &#039;me@example.com&#039;;

// Now do the custom part.
Zend_Feed::registerNamespace(&#039;myns&#039;, &#039;http://www.example.com/myns/1.0&#039;);

$entry-&gt;{&#039;myns:myelement_one&#039;} = &#039;my first custom value&#039;;
$entry-&gt;{&#039;myns:container_elt&#039;}-&gt;part1 = &#039;first nested custom part&#039;;
$entry-&gt;{&#039;myns:container_elt&#039;}-&gt;part2 = &#039;second nested custom part&#039;;

echo $entry-&gt;saveXML();
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.feed.consuming-atom-single-entry.html">Consuming a Single Atom Entry</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.feed.html">Zend_Feed</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.feed.custom-feed.html">Custom Feed and Entry Classes</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.feed.html">Zend_Feed</a></li>
  <li><a href="zend.feed.introduction.html">Introduction</a></li>
  <li><a href="zend.feed.importing.html">Importing Feeds</a></li>
  <li><a href="zend.feed.findFeeds.html">Retrieving Feeds from Web Pages</a></li>
  <li><a href="zend.feed.consuming-rss.html">Consuming an RSS Feed</a></li>
  <li><a href="zend.feed.consuming-atom.html">Consuming an Atom Feed</a></li>
  <li><a href="zend.feed.consuming-atom-single-entry.html">Consuming a Single Atom Entry</a></li>
  <li class="active"><a href="zend.feed.modifying-feed.html">Modifying Feed and Entry structures</a></li>
  <li><a href="zend.feed.custom-feed.html">Custom Feed and Entry Classes</a></li>
  <li><a href="zend.feed.reader.html">Zend_Feed_Reader</a></li>
  <li><a href="zend.feed.writer.html">Zend_Feed_Writer</a></li>
  <li><a href="zend.feed.pubsubhubbub.introduction.html">Zend_Feed_Pubsubhubbub</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>